home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 August: Tool Chest / Dev.CD Aug 94.toast / Sample Code / AppsToGo / Kibitz / Help.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-24  |  3.5 KB  |  144 lines  |  [TEXT/MPS ]

  1. /*
  2. ** Apple Macintosh Developer Technical Support
  3. **
  4. ** File:        help.c
  5. ** Written by:  Eric Soldan
  6. **
  7. ** Copyright © 1991-1992 Apple Computer, Inc.
  8. ** All rights reserved. */
  9.  
  10.  
  11.  
  12. /*****************************************************************************/
  13.  
  14.  
  15.  
  16. #include "Kibitz.h"                /* Get the Kibitz includes/typedefs, etc.    */
  17. #include "KibitzCommon.h"        /* Get the stuff in common with rez.        */
  18. #include "Kibitz.protos"        /* Get the prototypes for Kibitz.            */
  19.  
  20. #ifndef __BALLOONS__
  21. #include <balloons.h>
  22. #endif
  23.  
  24. #ifndef __PROCESSES__
  25. #include <Processes.h>
  26. #endif
  27.  
  28. #ifndef __UTILITIES__
  29. #include <Utilities.h>
  30. #endif
  31.  
  32.  
  33.  
  34. /*****************************************************************************/
  35. /*****************************************************************************/
  36.  
  37.  
  38.  
  39. #pragma segment Main
  40. void    DynamicBalloonHelp(void)
  41. {
  42.     WindowPtr            window, oldPort;
  43.     ProcessSerialNumber    cpsn, fpsn;
  44.     FileRecHndl            frHndl;
  45.     Point                mouseLoc, tip;
  46.     ControlHandle        ctl;
  47.     Rect                rct;
  48.     short                part, message, pos, i;
  49.     long                ref;
  50.     HMMessageRecord        helpMessage;
  51.     Boolean                procsSame;
  52.     static short        lastMessage;
  53.     static short        position[4] = {5, 6, 2, 1};
  54.  
  55.     if (gSystemVersion < 0x0700) return;
  56.         /* The system can't support balloons. */
  57.  
  58.     if ((!HMGetBalloons()) || (!IsAppWindow(FrontWindow()))) {
  59.         lastMessage = 0;
  60.         return;
  61.     }        /* Balloons have been turned off, or it isn't our window anymore. */
  62.  
  63.     HMGetBalloonWindow(&window);
  64.     if (!window) lastMessage = 0;
  65.         /* There is no balloon currently, so there is no last message. */
  66.  
  67.     tip = mouseLoc = GetGlobalMouse();
  68.     part = FindWindow(mouseLoc, &window);
  69.     if ((window != FrontWindow()) || (part != inContent)) {
  70.         lastMessage = 0;
  71.         return;
  72.     }        /* We aren't over the content of the front window, so leave. */
  73.  
  74.     GetCurrentProcess(&cpsn);
  75.     GetFrontProcess(&fpsn);
  76.     SameProcess(&cpsn, &fpsn, &procsSame);
  77.     if (!procsSame) {
  78.         lastMessage = 0;
  79.         return;
  80.     }        /* We aren't the front process, so leave. */
  81.  
  82.     GetPort(&oldPort);
  83.     frHndl = (FileRecHndl)GetWRefCon(window);
  84.     SetPort(window);
  85.     SetOrigin((*frHndl)->doc.arrangeBoard * 4096, 0);
  86.     GlobalToLocal(&mouseLoc);
  87.  
  88.     ctl = ((WindowPeek)window)->controlList;
  89.     while (ctl) {
  90.         rct = (*ctl)->contrlRect;
  91.         if (PtInRect(mouseLoc, &rct)) break;
  92.         ctl = (*ctl)->nextControl;
  93.     }        /* Find the control that we are over. */
  94.  
  95.     message = 0;
  96.     if (ctl) {
  97.         message = ref = GetControlReference(ctl);
  98.         message *= 2;
  99.         if (ref > 9) {
  100.             if (ctl == (*frHndl)->doc.gameSlider) {
  101.                 message = 24;
  102.                 if (!(*frHndl)->doc.numGameMoves) --message;
  103.             }
  104.             else {
  105.                 for (i = 0; i < 2; ++i) if ((TEHandle)ref == (*frHndl)->doc.message[i]) break;
  106.                 if (i < 2) message = 19 + i + i;
  107.                 else message = 0;
  108.             }
  109.         }
  110.         else
  111.             if (FindControl(mouseLoc, window, &ctl)) --message;
  112.                 /* Use regular message for active controls. */
  113.     }
  114.     else {
  115.         rct = PaletteRect();
  116.         if (PtInRect(mouseLoc, &rct)) message = 25;
  117.     }
  118.  
  119.     if (message) {
  120.         if (lastMessage != message) {    /* If this balloon isn't current balloon... */
  121.             lastMessage = message;
  122.             helpMessage.hmmHelpType             = khmmStringRes;
  123.             helpMessage.u.hmmStringRes.hmmResID = rDynHelpStrings;
  124.             helpMessage.u.hmmStringRes.hmmIndex = message;
  125.             LocalToGlobalRect(&rct);
  126.             pos = (tip.v > (rct.top + rct.bottom) / 2) ? 2 : 0;
  127.             if (tip.h > (rct.left + rct.right) / 2) ++pos;
  128.             pos = position[pos];
  129.             SetOrigin(0, 0);
  130.             HMShowBalloon(&helpMessage, tip, &rct, nil, 0, pos, kHMRegularWindow);
  131.         }
  132.     }
  133.     else {
  134.         if (lastMessage) HMRemoveBalloon();
  135.         lastMessage = 0;
  136.     }
  137.  
  138.     SetOrigin(0, 0);
  139.     SetPort(oldPort);
  140. }
  141.  
  142.  
  143.  
  144.